package cn.stylefeng.guns.modular.hxl.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.hxl.entity.HxlArea;
import cn.stylefeng.guns.modular.hxl.mapper.HxlAreaMapper;
import cn.stylefeng.guns.modular.hxl.model.params.HxlAreaParam;
import cn.stylefeng.guns.modular.hxl.model.result.HxlAreaResult;
import  cn.stylefeng.guns.modular.hxl.service.HxlAreaService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 好想来-仓库信息 服务实现类
 * </p>
 *
 * @author 
 * @since 2025-06-30
 */
@Service
public class HxlAreaServiceImpl extends ServiceImpl<HxlAreaMapper, HxlArea> implements HxlAreaService {

    @Override
    public void add(HxlAreaParam param){
        HxlArea entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(HxlAreaParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(HxlAreaParam param){
        HxlArea oldEntity = getOldEntity(param);
        HxlArea newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public HxlAreaResult findBySpec(HxlAreaParam param){
        return null;
    }

    @Override
    public List<HxlAreaResult> findListBySpec(HxlAreaParam param){
        return this.baseMapper.customList(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(HxlAreaParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(HxlAreaParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private HxlArea getOldEntity(HxlAreaParam param) {
        return this.getById(getKey(param));
    }

    private HxlArea getEntity(HxlAreaParam param) {
        HxlArea entity = new HxlArea();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
